<?php

namespace app\admin\controller;
use think\App;
use think\facade\Request;
use think\Validate;
use app\admin\model\AboutModel;
use app\admin\services\AboutService;

class About extends Common implements ICurd
{

    public function index()
    {

    }

    public function create()
    {

    }

    public function update()
    {
        if(request()->isPost()) {
            $editData = $this->mapping();
            $res = $this->getService()->save($editData,1);
            if( $res ){
                return $this->jsonSuccess('update');
            }
            return $this->jsonError();
        }else{
            $info = $this->getService()->getInfoById([
                'id',
                'content'
            ],1);
            $this->assign([
                'info' => $info
            ]);
            return view();
        }
    }

    public function remove()
    {
        // TODO: Implement remove() method.
    }

    public function detail()
    {
        // TODO: Implement detail() method.
    }

    public function setStatus()
    {
        // TODO: Implement setStatus() method.
    }

    private function getService()
    {
        return AboutService::makeInstance();
    }

    private function mapping()
    {
        $param = input('post.');
        $data = [
            'status' => (int)$param['status'] ?: 1,
            'is_delete' => (int)$param['is_delete'] ?: 1,
            'sort' => (int)$param['sort'] ?: 0,
            'content' => trim($param['content']) ?: "",
        ];
        return $data;
    }

}